#ifndef SETTINGWIDGET_H
#define SETTINGWIDGET_H

#include <QObject>
#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QPushButton>
#include <QListWidget>
#include <QStackedWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGuiApplication>
#include <QScreen>
#include <QPoint>
#include <QDebug>
#include <QFrame>
#include <QPushButton>
#include <QFrame>
#include <QTabBar>
#include <QTabWidget>
#include <QToolButton>
#include <QGSettings>
#include <QSettings>
#include <QStandardPaths>
#include <QDir>
#include <QFileDialog>
#include <QPainter>
#include <QStringList>
#include <QShortcut>
#include <QRadioButton>
#include <QStandardItemModel>
#include <QBoxLayout>

//#include "windowmanager/windowmanager.h"
//#include <system_information.hpp>
#include "kwindoweffects.h"
#include <KWindowEffects>

#include "utils/xatom-helper.h"
#include "global/global.h"
#include "shortcutlineedit.h"
#include "../../screencapsdk/kysdk-qtwidgets/kswitchbutton.h"
#include "../../screencapsdk/kysdk-qtwidgets/gsettings.hpp"
#include "camera/globalinstance.h"
#include "widgets/camerapage.h"
#include "utils/desktopinfo.h"
//#include "ukuiwindowhelper/ukuiwindowhelper.h"
class SettingWidget : public QWidget
{
    Q_OBJECT
public:
    explicit SettingWidget(QWidget *parent = nullptr);
    bool m_isMaximized = false;         //最大化和还原俩个状态
    bool m_isInitComplete = false;      //设置的数据是否初始化完成
    ~SettingWidget();
    kdk::KSwitchButton *m_cameraRecord;
    QComboBox *m_cameraDevice;          //摄像头设备列表
    QLineEdit *m_saveDirectory;
    QPushButton *m_btnBrowse;
    QComboBox *m_saveFormat;
    QComboBox *m_resolution;
    QComboBox *m_frameRate;
    QComboBox *m_microphone;            //麦克风设备名
    QComboBox *m_completionAction;
    void iniMicDevices(QStringList list); //QStringList list
    void micDevicesChanged(QStringList list);
    void setData(const QString &key, const QString &value);
    void closeCamera();
    void setSavePath(QString str);                  //省略显示保存路径
signals:
    void sigSavePathChanged(QString path);
    void sigSaveFormatChanged(QString format);
    void sigResolutionChanged(int resolution);
    void sigFrameRateChanged(QString frameRate);
    void sigMicrophoneChanged(QString microphone);
    void sigCompletionActionChanged(QString completionAction);
    void sigShortcutChanged(ShortcutRec type, QString ShortcutText);
    void sigCameraRecord(bool checked);
//    void sigUpdateResolution(V4l2DeviceInfo *device);

protected:
    void paintEvent(QPaintEvent *event) override;
    bool eventFilter(QObject *obj, QEvent *event) override ;
    void resizeEvent(QResizeEvent *event) override;

public slots:
    void slotShowMaximized();
    void slotStarRecording();
    void slotStopRecording();

private slots:
    void slotSaveSettingBtnClicked();
    void slotShortcutBtnClicked();
    void slotShowMinimized();
    void slotClose();
    void slotCameraRecordToggled(bool checked);
    void slotSelectSaveFiles();
    void slotSaveFormatChanged(int index);
    void slotResolutionChanged(int index);
    void slotFrameRateChanged(int index);
    void slotMicrophoneChanged(int index);
    void slotCompletionActionChanged(int index);

    void updateCurrentCamera(int x);        //选择当前摄像头

private:
    void initComponents();
    void setComponentsSize();
    void initLayout();
    void initLeftSidebarLayout();
    void initTitleLayout();
    void initPage1Layout();
    void initPage2Layout();
    void initComponentsvalue();     //设置初始值
    void initConnect();
    void initGsetting();     //监听主题变化
    void themeChange();      //主题变化
    void themeFontStyle(QString fontType, int fontSize); //字体字号变化
    void longText(QLabel *nameC);    //显示不全情况
    void transChange();      //控制面板变化
    void btnDefaultStyle(QToolButton *btn);        //左侧按钮的默认样式
    QString pluginBtnHoverColor(QString styleName, bool hoverFlag);

    QString dirNameELideText(QString str);          //获取路径的省略显示

    void showCurrentCamera();       //显示摄像头列表
    void elideCameraText();         //摄像头设备名称缩略显示
    void initCameraDevice();        //初始化摄像头
    QMap<QString,QString> SysNameTofullName;    //设备全名
    QMap<QString,QString> EasyNamyTosysName;    //缩略名-设备名
    QStandardItemModel *model = nullptr;


    QWidget *leftSidebar;

    QWidget *rightVWidget;          //窗口右侧
    QStackedWidget *stackedWidget;  //右侧切换页面
    QFrame *m_titleBar;
    QPushButton *m_minimumBtn;
    QPushButton *m_maximumBtn;
    QPushButton *m_closeBtn;
    QLabel *logoNameLabel = nullptr;

    //侧边栏
    QToolButton *saveSettingBtn;
    QToolButton *shortcutBtn;
    QLabel *labelIcon1;
    QLabel *labelText1;
    QLabel *labelIcon2;
    QLabel *labelText2;

    //页面1
    QWidget *page1 ;                //页面1
    QWidget *page1LabelWid;          //页的标签属性窗口
    QBoxLayout *page1LabelWidLayout;

    QWidget *m_cameraWid;
    QWidget *m_cameraDeviceWid;
    QWidget *m_saveDirectoryWid;    //每行标签属性窗口
    QWidget *m_saveDirAndBrowseWid;
    QWidget *m_saveFormatWid;
    QWidget *m_resolutionWid;
    QWidget *m_frameRateWid;
    QWidget *m_microphoneWid;
    QWidget *m_completionActionWid;

    QLabel *saveSetting;         // 页面1标题-保存设置（右侧1）

    QLabel *cameraRecord;        // 是否开启摄像头
    QLabel *cameraDevice;        // 摄像头列表
    QLabel *saveDirectory;       // 保存目录
    QLabel *saveFormat;          // 保存格式
    QLabel *resolution;          // 清晰度
    QLabel *frameRate;           // 视频帧率
    QLabel *microphone;          // 麦克风
    QLabel *completionAction;    // 完成后动作
//    UkuiWindowHelper *m_windowHelper = nullptr;


    //页面2
    QWidget *page2 ;
    QWidget *page2LabelWid;

    QWidget *m_invokeScreencapWid;
    QWidget *m_startRecordingWid;
    QWidget *m_pauseRecordingWid;
    QWidget *m_recordFullScreenWid;
    QWidget *m_recordWindowWid;
    QWidget *m_enableMicrophoneWid;

    QLabel *shortcut;

    QLabel *invokeScreencap;     // 唤起录屏应用
    QLabel *startRecording;      // 开始/结束录屏（右侧2）
    QLabel *pauseRecording;      // 暂停/继续录屏
    QLabel *recordFullScreen;    // 全屏录制
    QLabel *recordWindow;        // 窗口录制
    QLabel *enableMicrophone;    // 开启/关闭麦克风

    ShortcutLineEdit *m_invokeScreencap;
    ShortcutLineEdit *m_startRecording;
    ShortcutLineEdit *m_pauseRecording;
    ShortcutLineEdit *m_recordFullScreen;
    ShortcutLineEdit *m_recordWindow;
    ShortcutLineEdit *m_enableMicrophone;

    int themeColor = 0;
    QGSettings *qtSettings = nullptr;
    QString hoverColor;
    QString clickColor;
    double m_tran = 0.60;     //透明度

    //gsettings
    QGSettings *m_Data = nullptr;
    QGSettings *m_darkData = nullptr;
    QGSettings *m_styleSettings = nullptr;

    QStringList m_MicDevicesName;
    QString m_NoMic = tr("none mic");
    bool m_isInitMic = false;

    QString currentSaveFile;

    bool isCanShowCamera = true;   //默认可以显示摄像头，wayland不显示
    DesktopInfo m_info;
};

#endif // SETTINGWIDGET_H
